<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>车类型</title>
    <link href="//cdn.staticfile.org/layui/2.9.9/css/layui.css" rel="stylesheet">
    <script src="jq.js"></script>
    <script>
        // $(function () {
        //     loaddata()
        // })

        function updateCartype(tid){
            // alert(tid)
            location.href = 'cartypeEdit.html?tid='+tid
        }

        function delCartype(tid){
            layui.use(function(){
                var layer = layui.layer;
                layer.confirm(`tid:${tid} 确认要删除吗?`, {
                    btn: ['确定', '关闭'] //按钮
                }, function(){
                    $.ajax({
                        url: 'http://localhost:8080/cartype/delete',
                        type: 'DELETE',
                        data:{
                            tid:tid
                        },
                        dataType:'JSON',
                        success: function (res) {
                            console.log(res)
                            layer.msg('删除成功', {icon: 1});
                            loaddata()
                        }
                    })

                });
            })

        }

    </script>
</head>
<body>
<script src="//cdn.staticfile.org/layui/2.9.9/layui.js"></script>
<script>
    layui.use('table', function(){
        var table = layui.table;
        // 已知数据渲染
        var inst = table.render({
            elem: '#ID-table-demo-data',
            url:'http://localhost:8080/cartype/all',
            parseData: function(res){ // res 即为原始返回的数据
                console.log(res)
                return {
                    "code": 0, // 解析接口状态
                    "msg": res.msg, // 解析提示文本
                    // "count": res.total, // 解析数据长度
                    "data": res.data // 解析数据列表
                };
            },
            cols: [[ //标题栏
                {field: 'tid', title: 'ID', width: 80, sort: true},
                {field: 'name', title: '类型'},
                {width:200, title: '操作', templet: function (item){
                        return `
                                <button type="button" class="layui-btn layui-bg-purple layui-btn-sm" onclick="updateCartype(${item.tid})">修改</button>
                                <button type="button" class="layui-btn layui-bg-red layui-btn-sm" onclick="delCartype(${item.tid})">删除</button>`
                    }}
            ]],
        })
    })
</script>
<div class="layui-fluid">
    <div class="layui-row">
        <div class="layui-col-md10 layui-col-md-offset1">
            <h1>layui</h1>
            <a href="cartypeEdit.html" class="layui-btn">新增</a>
            <table class="layui-hide" id="ID-table-demo-data"></table>
        </div>
    </div>
</div>

</body>
</html>